Ext.onReady(function() {
			Ext.get(this.document).on('contextmenu', function(e, targetEl){
				var sel = document.getSelection();
				var pXY = this.getXY();
				var xy = e.getXY();
				if(this.menu) this.menu.destroy();
				this.menu = new Ext.menu.Menu({
					items: [{
						text: 'Add '+ sel
					,	ref: 'addAuthor'
					,	scope: this	
					,	hidden: true
					,	handler: function(){
							Ext.each(Ext.fly(this).select("span.tt-sciname").elements, function(el){
								if(targetEl.innerHTML == el.innerHTML){
									var authorship = document.createAttribute('authorship');
									authorship.nodeValue = sel;
									Ext.get(targetEl).addClass('authorship');
									el.attributes.setNamedItem(authorship);
								}
							});
						}  
					}, {
						ref: 'replaceAuthor'	
					,	scope: this	
					,	hidden: true	
					,	handler: function() { 
							Ext.each(Ext.fly(this).select("span.tt-sciname").elements, function(el){
								if(targetEl.innerHTML == el.innerHTML){
									var authorship = document.createAttribute('authorship');
									authorship.nodeValue = sel;
									el.attributes.setNamedItem(authorship);
								}
								
							});
						}
					},{
						ref: 'removeAuthor'	
					,	scope: this	
					,	hidden: true	
					,	handler: function() { 
							Ext.each(Ext.fly(this).select("span.tt-sciname").elements, function(el){
								if(targetEl.innerHTML == el.innerHTML){
									Ext.get(targetEl).removeClass('authorship');
									el.attributes.removeNamedItem('authorship');
								}
								
							});
						}
					}]
				});
			
				if (!Ext.isEmpty(sel)) {
					var auth = targetEl.getAttribute("authorship");
					if (auth == null) {
						this.menu.addAuthor.show();
					} else if(auth != sel){
						this.menu.replaceAuthor.show();
						this.menu.replaceAuthor.text = 'Replace ' + auth + ' to ' + sel;
					}
				}
				if(targetEl.hasAttribute("authorship")){
					this.menu.removeAuthor.text = 'Remove ' + targetEl.getAttribute("authorship");
					this.menu.removeAuthor.show();
				}
				this.menu.showAt(xy);
			}, null, {
					delegate: 'span.tt-sciname'
				,	stopEvent: true
			});


});